<?php
/**
 * Created by PhpStorm.
 * User: 秋刀鱼
 * Date: 2018/7/31
 * Time: 15:31
 */

namespace app\models;

use yii\base\Model;
use Yii;
use \common\helps\tools;//使用工具类

class SpecialOther extends Model
{
    //表名
    protected $table = '';

    /**
     * title 查询发放方式
     * @return array
     */
    public function selectGrank()
    {
        $query = new \yii\db\Query();

        $newInfo = $query->select(['id','content','create_time','update_time'])->from('data_yii.grank_way')->all();
        return $newInfo;
    }


    /**
     * title 查询专利类型
     * @return array
     */
    public function selectPatent()
    {
        $query = new \yii\db\Query();

        $patent = $query->select(['id','content','create_time','update_time'])->from('data_yii.patent_type')->all();
        return $patent;
    }


    /**
     * title 查询论文类型
     * @return array
     */
    public function selectThesis()
    {
        $query = new \yii\db\Query();

        $patent = $query->select(['id','content','create_time','update_time'])->from(tools::databaseName().'.thesis_type')->all();
        return $patent;
    }



    /**
     * title 获取论文类型名称
     * @return array|bool
     */
    public function thesisType($id)
    {
        $query = new \yii\db\Query();
        $find = $query->select(['id','content','create_time','update_time'])->from(tools::databaseName().'.thesis_type')->where(['id'=>$id])->one();

       return $find;

    }

    /**
     * title 获取专利类型名称
     * @return array|bool
     */
    public function patentType($id)
    {
        $query = new \yii\db\Query();
        $find = $query->select(['id','content','create_time','update_time'])->from(tools::databaseName().'.patent_type')->where(['id'=>$id])->one();

        return $find;

    }

    /**
     * title 查询项目名称
     * @param $uid
     * @return array
     */
    public function selectName($uid){

        $query = new \yii\db\Query();
        $result = $query->select(['b.id','b.project_id','b.project_name'])
            ->from(tools::databaseName().'.special_project_child AS b')
            ->rightJoin(tools::databaseName().'.special_project AS a', 'b.project_id = a.id')
            ->where(['a.create_id' => $uid,'a.status' => 2])
            ->all();
        return $result;


    }


    /**
     * title 查询项目进度
     * @param $child_id
     * @return array
     */
    public function selectStatus($child_id)
    {
        $query = new \yii\db\Query();
        $plan = $query->select(['id','user_id','plan_id','child_id'])->from(tools::databaseName().'.d_special_status')->where(['child_id'=>$child_id])->all();

        return $plan;
    }

    /**
     * title 根据专家管理id查询项目进度
     * @param $child_id
     * @return array
     */
    public function selectIdStatus($id)
    {
        $query = new \yii\db\Query();
        $plan = $query->select(['id','user_id','plan_id','child_id'])->from(tools::databaseName().'.d_special_status')->where(['id'=>$id])->all();

        return $plan;
    }


    /**
     * title 删除项目进度
     * @param $id
     * @return int
     * @throws \yii\db\Exception
     */
    public function delStatus($id)
    {
        $del = Yii::$app->db->createCommand()->delete(tools::databaseName(). '.' .'d_special_status', "user_id = '$id'")->execute();
        return $del;
    }


    /**
     * title 添加项目进度
     * @param $plan_id
     * @param $uid
     * @param $child_id
     * @return int
     * @throws \yii\db\Exception
     */
    public function addStauts($plan_id,$uid,$child_id,$special_id)
    {
        $field = ['plan_id','user_id','child_id','special_id'];
        $batchData = [[$plan_id,$uid,$child_id,$special_id]];
        $add = Yii::$app->db->createCommand()->batchInsert(tools::databaseName().'.'.'d_special_status', $field, $batchData)->execute();
        return $add;
    }



}